<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
{
	$email = mysql_real_escape_string($_REQUEST['email']);
	$fname = mysql_real_escape_string($_REQUEST['fname']);
	$lname = mysql_real_escape_string($_REQUEST['lname']);
	$name=$fname.$lname;
	$company = mysql_real_escape_string($_REQUEST['company']);
	$add = mysql_real_escape_string($_REQUEST['add1']);
	$city = mysql_real_escape_string($_REQUEST['city']);
	$code = mysql_real_escape_string($_REQUEST['code']);
	$state=mysql_real_escape_string($_REQUEST['state']);
	$count=mysql_real_escape_string($_REQUEST['select']);
	$phoneno = mysql_real_escape_string($_REQUEST['phoneno']);
	//$faxno = $_REQUEST['faxno'];
	
	$insert="INSERT INTO `tblorders`
		( `intcustomerid` , `varcustomername` , `varcustomercompanyname` ,
		 `varcustomerstreetaddress`	, `varcustomercity` , `varcustomerpostcode` , 
		 `varcustomerstate` , `varcustomercountry` , `varcustomertelephone` , 
		 `varcustomeremailid` , `vardeliveryname` , 	
`vardeliverycompany`,`vardeliverystreetaddress`,`vardeliverycity`,`vardeliverypostcode`,`vardeliverystate`,`vardeliverycountry`,`varbillingname`,`varbillingcompanyname`,`varbillingstreetaddress`,`varbillingcity`,`varbillingpostcode`,`varbillingstate`,`varbillingcountry`,`varpaymentmethod`,`dtlastmodified`,`dtdateadded`,`dtpurchased`,`intcurrentorderstatus`,`dtfinished`,`varcurrency`,`deccurrencyvalue` )
	
	VALUES ('0', '$name', '$company', '$add', '$city', '$code', '$state', '$count', '$phoneno', '$email', '$company','$company', '$add', '$city', '$code', '$state', '$count','$company','$company', '$add', '$city', '$code', '$state', '$count','0',NOW(),NOW(),NOW(),'1',NOW(),'0','0' )";

	$sql=$obj_db->insert($insert);	
	$ordid= mysql_insert_id($obj_db->CONN);
	header("location:telephoneorder.php?msg=add&orderid=".$ordid);
	die();
}	

// update shipping address
$pdname="";
$pname="";
$paddress="";
$pcity="";
$pcode="";
$pstate="";
$pcont="";
$action=1;

	if(isset($_REQUEST['action']) && trim($_REQUEST['action'])=="edit")
	{
		if(isset($_REQUEST['orderid']) && ($_REQUEST['orderid'])!="")
		{
		$ordid=$_REQUEST['orderid'];
		$sql =mysql_query( "select * from tblorders where intid ='$ordid'");
		
		while($num_rows= mysql_fetch_array($sql))
		{	
	    	$pdname=stripslashes($num_rows['vardeliveryname']);	
			$pname=stripslashes($num_rows['vardeliverycompany']);	
			$paddress=stripslashes($num_rows['vardeliverystreetaddress']);	
			$pcity=stripslashes($num_rows['vardeliverycity']);	
			$pcode=stripslashes($num_rows['vardeliverypostcode']);	
			$pstate=stripslashes($num_rows['vardeliverystate']);	
			$pcont=stripslashes($num_rows['vardeliverycountry']);	
			
		}
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
			//print_r($_REQUEST);
			$dname=mysql_real_escape_string($_REQUEST['company2']);
			$cname=mysql_real_escape_string($_REQUEST['company2']);
			$add=mysql_real_escape_string($_REQUEST['add12']);
			$city=mysql_real_escape_string($_REQUEST['city2']);
			$code=mysql_real_escape_string($_REQUEST['code2']);
			$state=mysql_real_escape_string($_REQUEST['state2']);
			$con=mysql_real_escape_string($_REQUEST['select2']);
			$sql_upd ="UPDATE `tblorders` SET `vardeliveryname` = '$dname',
			 			`vardeliverycompany` = '$cname',
						`vardeliverystreetaddress` = '$add', 
						`vardeliverycity` = '$city',
						`vardeliverypostcode`='$code',
						`vardeliverystate`='$state',
						`vardeliverycountry`='$con' 
						WHERE `intid`='$ordid'";
			
			echo $sql_upd."<br>";
			
			$sql=$obj_db->edit($sql_upd);
			
			
			header("location:telephoneorder.php?orderid=".$ordid);
			die();
			}
		}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<title>Welcome to Duntuk- admin module</title>
<link href="css/pain.css" rel="stylesheet" type="text/css" />
<link href="css/dunt.css" rel="stylesheet" type="text/css" />
</head>
<body >

<script language="javascript" src="js/scw.js"></script>
<script language="javascript" src="js/customer.js"></script>


<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td align="center" valign="top" ><?php include(INC."top.inc.php");?></td>
</tr>
<tr>
<td valign="top">

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td valign="top">
		<form name="f2" method="post" action="" >
		<?php 
	if(isset($_REQUEST['action']) && ($_REQUEST['action'])=="edit")
	{
	?>
	<table width="73%" align="center" cellpadding="2" cellspacing="2" class="border">
      <tr class="bg1">
        <td height="20" align="center"><strong> Edit customer shipping
          address</strong></td>
      </tr>
      <tr >
        <td><table width="88%" border="0" align="center" cellpadding="2" cellspacing="2">
            <?php
			if(isset($_REQUEST['mail_add']))
			{
				$email=$_REQUEST['mail_add'];
			}
			?>
            <tr>
              <td width="121" align="right" class="sltimg">&nbsp;</td>
              <td width="305" align="right">( All fields are Required)</td>
            </tr>
            <tr>
              <td align="right" class="sltimg">First Name : </td>
              <td><input name="fname2" type="text" class="textfield" id="fname2" size="35" value="<?php echo $pdname;?>" /></td>
            </tr>
            <tr>
              <td align="right" class="sltimg">Last Name : </td>
              <td><input name="lname2" type="text" class="textfield" id="lname2" size="35"  value="<?php echo $pname;?>"/></td>
            </tr>
            <tr>
              <td align="right" class="sltimg">Company : </td>
              <td><input name="company2" type="text" class="textfield" id="company2" size="35"  value="<?php echo $pname;?>"/></td>
            </tr>
            <tr>
              <td align="right" class="sltimg"><span class="fontsmall">Street Address</span> : </td>
              <td><input name="add12" type="text" class="textfield" id="add12" size="35"  value="<?php echo $paddress;?>"/></td>
            </tr>
            <tr>
              <td align="right" class="sltimg"><span class="fontsmall">City</span> : </td>
              <td><input name="city2" type="text" class="textfield" id="city2" size="35"  value="<?php echo $pcity;?>"/></td>
            </tr>
            <tr>
              <td align="right" class="sltimg"><span class="fontsmall">Postal Code </span> : </td>
              <td><input name="code2" type="text" class="textfield" id="code2" size="35"  value="<?php echo $pcode;?>"/></td>
            </tr>
            <tr>
              <td align="right" class="sltimg"><span class="fontsmall">State</span> : </td>
              <!--<td><select name="add" id="add">
			    <option>No</option>
			    <option value="1">home1</option>
			    <option value="2">home2</option>
			    </select></td>-->
              <td><input name="state2" type="text" class="textfield" id="state2" size="35"  value="<?php echo $pstate;?>"/></td>
            </tr>
            <tr>
              <td align="right" class="sltimg">Country : </td>
              <td><!--<select name="slt">
			    <option value="0">News Letter</option>
			    <option value="1">Subscribe</option>
			    <option value="2">Dont Subscribe</option>
			    </select>-->
                  <select name="select2" class="feature_headingbg">
                    <?php 
	  $sql3="select * from tblcountry";
	  $res=$obj_db->select($sql3);
	  if(count($res)>0)
	  {
	  for($c=0;$c<count($res);$c++)
	  {
	  ?>
                    <option value="<?php echo stripslashes($res[$c]['varcountryname']);?>">
                    <?php echo stripslashes($res[$c]['varcountryname']);?>
                    </option>
                    <?php }}?>
                </select></td>
            </tr>
            
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td colspan="2" align="center"><input name="Submit" type="submit" class="btn" id="Submit" 
				onclick="return check();" value="Update" />              </td>
            </tr>
        </table></td>
      </tr>
    </table> </form>
	<?php 
	}
	else
	{
	?>
	<form name="f1" method="post">
  <table width="73%" align="center" cellpadding="2" cellspacing="2" class="border">
	<tr class="bg1">
	<td height="20" align="center"><strong>
	  Add customer
	address</strong></td>
	</tr>	
	<tr >
	  <td>	  
	  <table width="88%" border="0" align="center" cellpadding="2" cellspacing="2">
			<?php
			if(isset($_REQUEST['mail_add']))
			{
				$email=$_REQUEST['mail_add'];
			}
			?>
			<tr>
			  <td width="121" align="right" class="sltimg">&nbsp;</td>
			  <td width="305" align="right">( All fields are Required)</td>
			  </tr>
			<tr>
			  <td align="right" class="sltimg">First Name : </td>
			  <td><input name="fname" type="text" class="textfield" id="fname" size="35" /></td>
			  </tr>
			<tr>
			  <td align="right" class="sltimg">Last Name : </td>
			  <td><input name="lname" type="text" class="textfield" id="lname" size="35" /></td>
			  </tr>
		
			<tr>
			  <td align="right" class="sltimg">E-mail</td>
			  <td><input name="email" type="text" class="textfield" id="email" size="35" /></td>
			  </tr>
			<tr>
			  <td align="right" class="sltimg">Company : </td>
			  <td><input name="company" type="text" class="textfield" id="company" size="35" /></td>
			</tr>
			
			
			<tr>
			  <td align="right" class="sltimg"><span class="fontsmall">Street Address</span> : </td>
			  <td><input name="add1" type="text" class="textfield" id="add1" size="35" /></td>
			  </tr>
			
			
			<tr>
			  <td align="right" class="sltimg"><span class="fontsmall">City</span> : </td>
			  <td><input name="city" type="text" class="textfield" id="city" size="35"/></td>
			</tr>			
			<tr>
			  <td align="right" class="sltimg"><span class="fontsmall">Postal Code </span> : </td>
			  
			  <td><input name="code" type="text" class="textfield" id="code" size="35"/></td>
			</tr>
			
			
			
			
			
			
			<tr>
			  <td align="right" class="sltimg"><span class="fontsmall">State</span> : </td>
			  <!--<td><select name="add" id="add">
			    <option>No</option>
			    <option value="1">home1</option>
			    <option value="2">home2</option>
			    </select></td>--><td><input name="state" type="text" class="textfield" id="state"	size="35"/></td>
			</tr>
			
			
			<tr>
			  <td align="right" class="sltimg">Country : </td>
			  <td><!--<select name="slt">
			    <option value="0">News Letter</option>
			    <option value="1">Subscribe</option>
			    <option value="2">Dont Subscribe</option>
			    </select>-->
			    <select name="select" class="feature_headingbg">
                  <?php 
	  $sql3="select * from tblcountry";
	  $res=$obj_db->select($sql3);
	  if(count($res)>0)
	  {
	  for($c=0;$c<count($res);$c++)
	  {
	  ?>
                  <option value="<?php echo $res[$c]['varcountryname'];?>">
                    <?php echo $res[$c]['varcountryname'];?>
                    </option>
                  <?php }}?>
                </select></td>
			  </tr>
			<tr>
			  <td align="right" class="sltimg">Phone : </td>
			  <td><input name="phoneno" type="text" class="textfield" id="phoneno" size="35" /></td>
			</tr>
			
			<?php
			if(isset($_REQUEST['cell']))
			{
				$cell=$_REQUEST['cell'];
			}
			?>
			<tr>
			  <td>&nbsp; </td>
			  <td>&nbsp;</td>
			</tr>
			<tr>
			  <td colspan="2" align="center">
				<input name="Submit" type="submit" class="btn" 
				onClick="return check();" value="Submit">	</td>
			</tr>
	  	</table> 	  </td>
	</tr>
	</table>
	<?php }?>
	
        </form>
</td>
      </tr>
    </table></td>
  </tr>
</table>

</td>
</tr>
<tr><td align="center">&nbsp;</td>
</tr>
</table>
</body>
</html>